<html>
<head>
<meta charset="UTF-8">
<title>内部模型数据清洗修改</title>
	<link id="easyuiTheme"  href="../../static/easyui/themes/bootstrap/easyui.css" rel="stylesheet" type="text/css"/>
	<link href="../../static/easyui/themes/icon.css" rel="stylesheet" type="text/css"/>
	<link href="../../static/css/esaas-easyui-edit.css" rel="stylesheet" type="text/css"/>
	<script src="../../static/easyui/jquery.min.js" type="text/javascript"></script>
	<script src="../../static/easyui/jquery.cookie.js" type="text/javascript"></script>
	<script src="../../static/easyui/ui-theme.js" type="text/javascript"></script>
	<script src="../../static/easyui/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../static/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.util.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.jquery.ajax.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.easyui.util.js" type="text/javascript"></script>
	<script src="../../ffres/dict/all.js" type="text/javascript"></script>
	<a href="" target="_blank" id="commonLink" name="commonLink"></a>
</head>
<body class="easyui-layout" scroll="no">
	<form id="ff" method="post">
		<div class="esaas-info-title">内部模型数据清洗信息</div>
		<table class="esaas-info-edit-table">
			<tr hidden="true">
				<td width="15%" align="right">清洗标识：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
					name="tranId" data-options="required:false"
					style="width: 100%; height: 25px;"></input></td>
				<td width="15%" align="right">应用模型标识：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
					name="appModelId" data-options="required:false"
					style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr>
				<td width="15%" align="left">清洗目标类型：</td>
				
				<td width="15%" align="left">清洗字段：</td>
				
				<td width="15%" align="left">清洗方法：</td>
				
			</tr>
			<tr>
				<td width="35%" style="vertical-align:top"><select class="easyui-combobox"
					id="tranTargetType" name="tranTargetType"
					style="width: 100%; height: 25px;"
					data-options="required:false,editable:false,valueField:'enname',textField:'cnname',data:TRAN_TARGET_TYPE,onChange:tranTypeChange">
				</select></td>
				<td width="35%" style="vertical-align:top">
					<ul class="easyui-datalist" id="tranFieldCodeList" data-options="valueField:'paramFieldCode', textField:'text'"></ul>
				</td>
				<td width="35%" style="vertical-align:top"><select class="easyui-combobox"
					id="tranFuncId" name="tranFuncId"
					style="width: 100%; height: 25px;"
					data-options="required:true,editable:false,valueField:'enname',textField:'cnname',data:TRAN_FUNC_ID">
				</select></td>
			</tr>
			<tr hidden="true">
				<td width="15%" align="right">清洗字段名称：</td>
				<td width="35%"><input class="easyui-textbox" type="text"
					name="tranFieldName" data-options="required:false"
					style="width: 100%; height: 25px;"></input></td>
				
			</tr>
		</table>
	</form>
	<div style="text-align: center; padding: 15px">
		<a href="javascript:void(0)" class="easyui-linkbutton"
			onclick="submitForm()">&nbsp;保&nbsp;存&nbsp;</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			onclick="closeForm()">&nbsp;关&nbsp;闭&nbsp;</a>
	</div>
	<script>
		var appId = $.getUrlParam('appId');
		var tran = null, appModelId;
		var tranId = $.getUrlParam('tranId');
		$(function() {
			$.restfulGet('../../api/isrv/tran/info/'+tranId,null,function(data){
					tran = data.rows;
					appModelId = data.rows.appModelId;
					$('#ff').form('load', {
						tranId : data.rows.tranId,
						appModelId : data.rows.appModelId,
						tranTargetType : data.rows.tranTargetType,
						fieldCode : data.rows.fieldCode,
						fieldName : data.rows.fieldName,
						tranFuncId : data.rows.tranFuncId
					});					
			});
		});
	
		function submitForm() {
			if (!$('#ff').form('validate'))
				return;

			var tranFieldSelected = $('#tranFieldCodeList').datagrid('getSelected');
			if (!tranFieldSelected) {
				$.messager.alert('提示','请选择一条清洗字段！','info');
				return;
			}
			var jsonData = $("#ff").serializeJson();
			jsonData.fieldCode = tranFieldSelected.paramFieldCode;
			jsonData.fieldName = tranFieldSelected.paramFieldName
			jsonData.appModelId = appModelId

			$.restfulPut('../../api/isrv/tran/info' ,jsonData, function(data) {
				window.parent.reloadList();
			});
		};

		function tranTypeChange(newValue, oldValue) {
			var selectIndex = -1, fieldCode = tran.fieldCode;
			if (newValue == '2') {
				var objectId;
				$.restfulGet('../../api/app/model/info/' + appModelId,null,function(data){
					objectId = data.rows.tableModelId;
					var url = `../../api/model/table/fields`;
                    $.restfulPostForm(url, {
						objectId: objectId ,
						size: 100
					}, function(data) {
						var rows = data.rows;
						if (rows && rows.length > 0 ) {
							rows.forEach( (f, index) => {
								f.paramFieldCode = f.fieldCode;
								f.paramFieldName = f.fieldName;
								f.text = `${f.fieldCode} ${f.fieldName ? f.fieldName : ''}`;
								if (fieldCode && fieldCode == f.paramFieldCode) {
									selectIndex = index
								}
							})
							$('#tranFieldCodeList').datalist({data: rows})
							if (selectIndex != -1 ) {
								$('#tranFieldCodeList').datalist('selectRow', selectIndex)
							}
						}
						
                    });
                });
			} else {
				var ioType = newValue == "1" ? "I" : "O"
				$.restfulPostForm(`../../api/isrv/inout/infos`, {
					ioType: ioType,
					appModelId : appModelId
				}, function(data){
					data.rows.forEach((f, index) =>{
						f.text = `${f.paramFieldCode} ${f.paramFieldName ? f.paramFieldName: "" }`
						if (fieldCode && fieldCode == f.paramFieldCode) {
							selectIndex = index
						}
					})
					$('#tranFieldCodeList').datalist({data: data.rows})
					if (selectIndex != -1 ) {
						$('#tranFieldCodeList').datalist('selectRow', selectIndex)
					}
				})
			}
			
		}
		
		function closeForm(){
			window.parent.JLEUtil.closewin();
		}
	</script>
</body>
</html>
